<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class search extends CI_Controller {


	public function index()
	{
		$all_session = $this->session->all_userdata();
		//////////////////////////////////////////////////////
		//////////////////// pagination //////////////////////
		//////////////////////////////////////////////////////

		$this->load->library('pagination');
		$config['first_tag_open'] = $config['last_tag_open']= $config['next_tag_open']= $config['prev_tag_open'] = $config['num_tag_open'] = '<li>';
        $config['first_tag_close'] = $config['last_tag_close']= $config['next_tag_close']= $config['prev_tag_close'] = $config['num_tag_close'] = '</li>';
        $config['cur_tag_open'] = "<li><span><b>";
        $config['cur_tag_close'] = "</b></span></li>";

		$config['base_url'] = base_url().'index.php/search/index';
		$config['per_page'] = 50;
				 
		$per_page = $config['per_page'];
		$uri = $this->uri->segment(3);

		//////////////////////////////////////////////////////
		/////////////////// end pagination /////x//////////////
		//////////////////////////////////////////////////////

		$id = @$all_session['login'][0]['mem_id'];
		$data['member'] = $this->main_model->get_member($id);

		$data['web_service'] = $this->main_model->get_web_service();
		
		
		$input = array(
			'search' => $this->input->post('search')
		);

		//////////////////////////////////////////////////////
		//////////////////////// search //////////////////////
		//////////////////////////////////////////////////////
		if($this->input->post('search') == null)
		{
			if(@$all_session != null)
			{
				$input = array(
					'search' => @$all_session['search']
				);
			}

		} else {			
			$session['search'] = $this->input->post('search');
			$this->session->set_userdata($session);

			$input = array(
				'search' => $this->input->post('search')
			);
		}

		//////////////////////////////////////////////////////
		///////////////////// result by //////////////////////
		//////////////////////////////////////////////////////

		if($this->input->post('result_by') == null)
		{
			$result_by = 'vdo.vdo_id';

			if(@$all_session['result_by'] != null)
			{
				$result_by = $all_session['result_by'];
			}
			
		} else {
			$result_by = $this->input->post('result_by');
			$session['result_by'] = $result_by;
			$this->session->set_userdata($session);				

		}

		//////////////////////////////////////////////////////
		//////////////////// category by /////////////////////
		//////////////////////////////////////////////////////
		if($this->input->post('category_by') == null)
		{
			$category_by = 'all';

			if(@$all_session['category_by'] != null)
			{
				$category_by = $all_session['category_by'];
			}

		} else {
			$category_by = $this->input->post('category_by');			
			$session['category_by'] = $category_by;
			$this->session->set_userdata($session);
			
		}


		//////////////////////////////////////////////////////
		/////////////////////// data /////////////////////////
		//////////////////////////////////////////////////////
		
		$data['search'] = $this->search_model->index($input ,$per_page ,$uri ,$result_by ,$category_by);
		
		$config['total_rows'] = count($this->search_model->count_index($input ,$result_by ,$category_by));



		$data['category'] = $this->pvdo_model->get_category();
		$this->pagination->initialize($config);


		$this->load->view('search',$data);
		

	}


	
}